package com.mySchool.controller;

import com.mySchool.anno.SysLog;
import com.mySchool.entity.*;
import com.mySchool.entity.DTO.*;
import com.mySchool.service.*;
import io.swagger.v3.oas.annotations.*;
import io.swagger.v3.oas.annotations.tags.*;
import lombok.extern.slf4j.*;
import org.springframework.beans.factory.annotation.*;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* @author : Hinton
* @date : 2024/10/18 上午9:28
*/
@RestController
@RequestMapping("/book")
@Slf4j
@Tag(name = "书籍")
public class BookController {
    @Autowired
    private BookService bookService;


    /**
     * 插入
     * @param bookInsertRequest  携带认证参数的book
     * @return
     */
    @PostMapping("/insert")
    @SysLog("新增书本")
    @Operation(summary = "新增书本", description = "插入书本")
    public Result<BookInsertResponse> insert(@RequestBody Request<BookInsertRequest> bookInsertRequest) {
        BookInsertResponse insertResponse = bookService.insert( bookInsertRequest.getParam());
        return Result.success(insertResponse);
    }

    @DeleteMapping
    @SysLog("删除书本")
    public Result delete(@RequestBody Request<List<Integer>> request) {
        bookService.delete(request.getParam());
        return Result.success();
    }


    @PutMapping("/update")
    @SysLog("更新书本")
    public Result update(@RequestBody Request<BookUpdateRequest> bookUpdateRequest) {

        bookService.update(bookUpdateRequest.getParam());

        return Result.success();
    }


    /**
     * 查找书明细
     * @param request  书名
     * @return
     */
    @GetMapping("/findDetail")
    public Result<PageResult<BookDetailResponse>> queryDetailByName(@RequestBody Request<BookDetailQueryRequest> request) {
        PageResult<BookDetailResponse> list = bookService.queryHigher(request.getParam());
        return Result.success(list);
    }


    /*
        1. 切面
         1.1 验权-- 授权的用户才能调用
         1.2 记录日志-- (1) 系统本身的监控 , 多少QPS, 成功率, (2) 排查问题,自证清白
         1.3 限流-- 授权每个用户的QPS, 1秒最多调用100次.
         1.4 异常的兜底-- 为了保证全部返回Result对象
         1.5 幂等(读写接口的区别),  access_key + nonce, 先去DB查一次, (1)查到了,返回value, (2)没有查到, 执行, 返回前,写幂等表    DB 表 ( key, value.)

        */

}
